//
//  FCLeftBarVC.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/2/26.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCLeftBarVC.h"
#import "FCAddCoinsModel.h"
#import "FCSettingModel.h"
#import "FCManageCoinsVC.h"
#import "XLSlideMenu.h"
#import "FCBaseNavigationVC.h"
#import "FCChangePinVC.h"
#import "FCChangePasswordVC.h"
#import "FCSelectLanguageVC.h"
#import "FCAboutAppVC.h"
#import "FCTransationFeesVC.h"
#import "FCExchangeRatesVC.h"
#import "FCLoginVC.h"
#import "FCFirstVC.h"
#import "FCLeftCoinsCell.h"
#import "FCLeftSettingCell.h"
#import "FCSettingFingerVC.h"
@interface FCLeftBarVC ()<UITableViewDelegate,UITableViewDataSource>
/* tableView */
@property (strong, nonatomic) UITableView *tableView;

/* viewline */
@property (strong, nonatomic) UIView *lineView;

/* 货币数据源 */
@property (strong, nonatomic) NSMutableArray  *coinsArray;
/* 设置 */
@property (strong, nonatomic) NSMutableArray *setArr;
/* 组头 */
@property (strong, nonatomic) NSArray *titleArr;
//要清除的的数据大小
@property(nonatomic,assign)float fileSize;
/* FCExchangeRatesVC */
@property (strong, nonatomic) FCExchangeRatesVC *exchangeRateVC;
/* 所有钱包硬币 */
@property (strong, nonatomic) NSMutableArray *allWalletArr;

/* <#Annotation#> */
@property (strong, nonatomic) NSMutableArray *arrMut;
@property (strong, nonatomic) FCWalletsModel *walletModel1;
@property (strong, nonatomic) FCWalletsModel *walletModel2;
@property (strong, nonatomic) FCWalletsModel *walletModel3;
@property (strong, nonatomic) FCWalletsModel *walletModel4;
@property (strong, nonatomic) FCWalletsModel *walletModel5;

@property (copy, nonatomic) NSString *cchStatus;
@end

@implementation FCLeftBarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    
    FCCCHStatusModel *model = [FCLocalUserHelper getCCHstatusModel];
    self.cchStatus = model.statusStr;
//    [self getCCHStatus];
    //主页移除货币的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removeCoins) name:@"removeCoins" object:nil];
    //管理货币添加或者移除的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leftChangeReloadWallet) name:@"leftChangeReloadWallet" object:nil];
    
    _titleArr = @[Localized(@"钱包"),Localized(@"设置"),Localized(@"关于我们"),Localized(@"退出")];
    [self loadCoinsData];
    [self loadSetData];
    //设置ui
    [self setupUI];
    [self loadAllWallet];
    
}

-(void)removeCoins{
    
    [self loadAllWallet];
}
-(void)leftChangeReloadWallet{
    
    [self loadAllWallet];
}
#pragma mark-UITableViewDelegate

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                
                
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
                
                
                
            }
                break;
            case 1:
            {
                
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 2:
            {
               
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 3:
            {
              
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 4:
            {
                
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            default:
                break;
        }
    }else if (indexPath.section == 1){
        
        switch (indexPath.row) {
            case 0:
            {
                
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
                
                
                
            }
                break;
            case 1:
            {
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 2:
            {
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 3:
            {
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 4:
            {
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            case 5:
            {
                
                FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = kOrderColor;
            }
                break;
            default:
                break;
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                FCWalletsModel *model = self.allWalletArr[indexPath.row];
                NSLog(@"货币id是%@",model.walletId);
                NSDictionary *dict = @{@"walletId":model.walletId,@"index":[NSString stringWithFormat:@"%zd",indexPath.row]};
                [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeWalletId" object:nil userInfo:dict];
                [FCLocalUserHelper saveDidScroll:model.walletId];
               
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
                
                
                
            }
                break;
            case 1:
            {
                FCWalletsModel *model = self.allWalletArr[indexPath.row];
                NSLog(@"货币id是%@",model.walletId);
                NSDictionary *dict = @{@"walletId":model.walletId,@"index":[NSString stringWithFormat:@"%zd",indexPath.row]};
                [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeWalletId" object:nil userInfo:dict];
                [FCLocalUserHelper saveDidScroll:model.walletId];
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
            }
                break;
            case 2:
            {
                FCWalletsModel *model = self.allWalletArr[indexPath.row];
                NSLog(@"货币id是%@",model.walletId);
                NSDictionary *dict = @{@"walletId":model.walletId,@"index":[NSString stringWithFormat:@"%zd",indexPath.row]};
                [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeWalletId" object:nil userInfo:dict];
                [FCLocalUserHelper saveDidScroll:model.walletId];
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
            }
                break;
            case 3:
            {
                FCWalletsModel *model = self.allWalletArr[indexPath.row];
                NSLog(@"货币id是%@",model.walletId);
                NSDictionary *dict = @{@"walletId":model.walletId,@"index":[NSString stringWithFormat:@"%zd",indexPath.row]};
                [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeWalletId" object:nil userInfo:dict];
                [FCLocalUserHelper saveDidScroll:model.walletId];
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
            }
                break;
            case 4:
            {
                FCWalletsModel *model = self.allWalletArr[indexPath.row];
                NSLog(@"货币id是%@",model.walletId);
                NSDictionary *dict = @{@"walletId":model.walletId,@"index":[NSString stringWithFormat:@"%zd",indexPath.row]};
                [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeWalletId" object:nil userInfo:dict];
                [FCLocalUserHelper saveDidScroll:model.walletId];
                FCLeftCoinsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
                cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
            }
                break;
            default:
                break;
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self.xl_sldeMenu showRootViewControllerAnimated:YES];
        });
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        
        
        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
        
        [self.xl_sldeMenu showRootViewControllerAnimated:true];
        FCChangePinVC *vc = [FCChangePinVC new];
        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
        [nav pushViewController:vc animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 2) {
        
        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
        
        [self.xl_sldeMenu showRootViewControllerAnimated:true];
        FCChangePasswordVC *vc = [FCChangePasswordVC new];
        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
        [nav pushViewController:vc animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 3) {
        
        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
        
        [self.xl_sldeMenu showRootViewControllerAnimated:true];
        FCSelectLanguageVC *vc = [FCSelectLanguageVC new];
        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
        [nav pushViewController:vc animated:YES];
    }
    
//    if (indexPath.section == 1 && indexPath.row == 1) {
//
//        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
//        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
//
//        [self.xl_sldeMenu showRootViewControllerAnimated:true];
//        FCTransationFeesVC *vc = [FCTransationFeesVC new];
//        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
//        [nav pushViewController:vc animated:YES];
//    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
        
        NSString *walletId = [FCLocalUserHelper getDidScrollWallId];
        //记录一下id
        if ([walletId isEqualToString:@"1009"]) {
            [self showAlert:Localized(@"CCH暂时不支持，敬请期待")];
            return;
        }
        [self.xl_sldeMenu showRootViewControllerAnimated:true];
        self.exchangeRateVC = [FCExchangeRatesVC new];
        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
        [nav pushViewController:self.exchangeRateVC  animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row == 4) {
        
        FCLeftSettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
        cell.nameLabel.textColor = HEXCOLOR(0x006fb6);
        //清除缓存
        
        [self alertView];
    }
    if (indexPath.section == 1 && indexPath.row == 5) {
        
        [self.xl_sldeMenu showRootViewControllerAnimated:true];
        FCSettingFingerVC *vc = [FCSettingFingerVC new];
        UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
        [nav pushViewController:vc  animated:YES];
    }
}
#pragma mark-货币管理
-(void)manageCoinsBtnClick{
    [self.xl_sldeMenu showRootViewControllerAnimated:true];
    FCManageCoinsVC *vc = [FCManageCoinsVC new];
    UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
    [nav pushViewController:vc animated:YES];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60*KScreenHeightScale1334;
}
#pragma mark-UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
        {
            //通过属性记录是否展开(默认不展开)
            FCAddCoinsModel *model = self.coinsArray[section];
            return model.isFolded? 0: self.allWalletArr.count;
        }
            break;
        case 1:
        {
            FCSettingModel *model = _setArr[section];
            return model.isFolded? 0: 6;
        }
            break;
        case 2:
        {
            return 0;
        }
            break;
        case 3:
        {
            return 0;
        }
            break;
            
        default:
            break;
    }
    
    return 0;
}
//设置headerView高度
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 100*KScreenHeightScale1334;
    }
    return 60*KScreenHeightScale1334;
}
//对hearderView进行编辑
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidthScale750, 65*KScreenHeightScale1334)];
    view.backgroundColor = kWhiteColor;
    
    //打开
    UIButton *openBtn = [UIButton new];
    [view addSubview:openBtn];
    [openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    [openBtn setImage:[UIImage imageNamed:@"btn_on"] forState:UIControlStateNormal];
    openBtn.tag = 200 + section;
    //添加事件
    [openBtn addTarget:self action:@selector(animationClick:) forControlEvents:UIControlEventTouchUpInside];
    //组头label
    UILabel *headerLabel = [UILabel new];
    [view addSubview:headerLabel];
    [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.top.mas_equalTo(0);
    }];
    headerLabel.font = Kfont(36);
    headerLabel.text = _titleArr[section];
    if (section == 0) {
        UIButton *manageCoinsBtn = [UIButton new];
        [view addSubview:manageCoinsBtn];
        [manageCoinsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(60*KScreenWidthScale750);
            make.top.mas_equalTo(headerLabel.mas_bottom).offset(3);
            
        }];
        [manageCoinsBtn setTitle:Localized(@"管理加密货币") forState:(UIControlStateNormal)];
        [manageCoinsBtn setTitleColor:kOrderColor forState:UIControlStateNormal];
        manageCoinsBtn.titleLabel.font = Kfont(28);
        [manageCoinsBtn addTarget:self action:@selector(manageCoinsBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    if (section == 0) {
        
        FCAddCoinsModel *model = _coinsArray[section];
        if (model.folded) {
            // 形变
            [UIView animateWithDuration:1.0 animations:^{
                
                openBtn.transform = CGAffineTransformRotate(self.view.transform, -M_PI);
            }];
        }else{
            
        }
    }else if (section == 1){
        FCSettingModel *model = _setArr[section];
        if (model.folded) {
            
            // 形变
            [UIView animateWithDuration:1.0 animations:^{
                
                openBtn.transform = CGAffineTransformRotate(self.view.transform, -M_PI);
            }];
        }else{
           
        }
        
    }else{
        openBtn.hidden = YES;
    }
    if (section == 2) {
        UIButton *aboutAppBtn = [UIButton new];
        [view insertSubview:aboutAppBtn atIndex:99];
        [aboutAppBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [aboutAppBtn addTarget:self action:@selector(aboutAppBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }else if (section == 3){
        
        UIButton *logoutBtn = [UIButton new];
        [view insertSubview:logoutBtn atIndex:99];
        [logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [logoutBtn addTarget:self action:@selector(logoutBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return view;
    
}
#pragma mark-按钮点击事件
//关于app
-(void)aboutAppBtnClick{
    
    [self.xl_sldeMenu showRootViewControllerAnimated:true];
    FCAboutAppVC *vc = [FCAboutAppVC new];
    UINavigationController *nav = (UINavigationController *)self.xl_sldeMenu.rootViewController;
    [nav pushViewController:vc animated:YES];
}
-(void)logoutBtnClick{
    
    //    [FCLocalUserHelper cleanTokenStr];
    //    [FCLocalUserHelper cleanXidStr];
    //    [FCLocalUserHelper cleanUserEmailStr];
    [self alertController];
    
}
-(void)animationClick:(UIButton*)sender{
    
    FCAddCoinsModel *model = _coinsArray[sender.tag - 200];
    model.folded = !model.isFolded;
    FCSettingModel *model1 = _setArr[sender.tag - 200];
    model1.folded = !model.isFolded;
    [self.tableView reloadData];
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"userCell"];
//    cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"userCell"];
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    switch (indexPath.section) {
        case 0:
        {
            
            FCLeftCoinsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
            cell = [[FCLeftCoinsCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell1"];
            FCWalletsModel *model = self.allWalletArr[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.walletModel = model;
            return cell;
        }
            break;
        case 1:
        {
            NSArray *arr = @[Localized(@"汇率"),Localized(@"更改PIN码"),Localized(@"更改密码"),Localized(@"语言"),Localized(@"清除缓存"),Localized(@"指纹")];
            FCLeftSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
            cell = [[FCLeftSettingCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell2"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.nameLabel.text = arr[indexPath.row];
            
            return cell;
        }
            break;
        case 2:
        {
            
        }
            break;
        case 3:
        {
            
        }
            break;
        default:
            break;
    }
    
    return nil;
    
}

//懒加载tableView
-(UITableView*)tableView{
    
    if(!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView ];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.lineView.mas_bottom);
            make.left.mas_offset(0);
            make.right.mas_offset(0);
            make.bottom.mas_offset(0);
        }];
        [_tableView setScrollEnabled:NO];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.backgroundColor = [UIColor clearColor];
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
-(void)loadCoinsData{
    if (!_coinsArray) {
        _coinsArray = [[NSMutableArray alloc]init];
    }
    NSArray *arr = @[@"Manage Coins",@"比特币",@"莱特币",@"方格币",@"妈卖批"];
    for (NSMutableArray *name in arr) {
        FCAddCoinsModel *model = [[FCAddCoinsModel alloc]initWithItem:name];
        [_coinsArray addObject:model];
    }
    
}
-(void)loadSetData{
    
    if (!_setArr) {
        _setArr = [[NSMutableArray alloc]init];
    }
    NSArray *arr = @[@"Exchange Rates",@"Transation Fees",@"Change PIN",@"Change Password",@"Langauge",@"Clear Cache"];
    for (NSMutableArray *name in arr) {
        FCSettingModel *model = [[FCSettingModel alloc]initWithItem:name];
        [_setArr addObject:model];
    }
}
#pragma mark-设置UI
-(void)setupUI{
    //头部图标
    UIImageView *topIconImageView = [UIImageView new];
    [self.view addSubview:topIconImageView];
    [topIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            if (iPhoneX) {
                
                make.left.mas_equalTo(30*KScreenWidthScale750);
                make.top.mas_equalTo(64);
                make.height.mas_equalTo(54*KScreenHeightScale1334);
                make.width.mas_equalTo(316*KScreenWidthScale750);
            }else{
                make.left.mas_equalTo(30*KScreenWidthScale750);
                make.top.mas_equalTo(64);
                make.height.mas_equalTo(54*KScreenHeightScale1334);
                make.width.mas_equalTo(316*KScreenWidthScale750);
            }
        }else{
            make.left.mas_equalTo(30*KScreenWidthScale750);
            make.top.mas_equalTo(64);
            make.height.mas_equalTo(54*KScreenHeightScale1334);
            make.width.mas_equalTo(316*KScreenWidthScale750);
        }
    }];
    topIconImageView.image = [UIImage imageNamed:@"logo_profile"];
    
    //分割线
    UIView *viewLine =[UIView new];
    self.lineView = viewLine;
    [self.view addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(topIconImageView.mas_bottom).offset(60*KScreenHeightScale1334);
        make.height.mas_equalTo(1);
    }];
    viewLine.backgroundColor =kLineColor;
    //tableView
    [self tableView];
}

-(void)alertController{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Localized(@"提示") message:[NSString stringWithFormat:Localized(@"确定要退出吗？")] preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [FCLocalUserHelper saveLoginStates:@"0"];
        FCFirstVC *login = [FCFirstVC new];
        FCBaseNavigationVC *nvc = [[FCBaseNavigationVC alloc]init];
        nvc.viewControllers = @[login];
        /* 设置主控制器 */
        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        window.rootViewController = nvc;
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"取消") style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)alertView
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Localized(@"提示") message:[NSString stringWithFormat:Localized(@"确定要清除缓存吗?")] preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [FCLocalUserHelper deleteFMDBExchangeRatesModel];
        [FCLocalUserHelper cleanFMDBCurrentResultModel];
        [self showAlert:Localized(@"已清除")];
        [FCLocalUserHelper pushMainTabbarController];
        
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"取消") style:UIAlertActionStyleCancel handler:nil]];
    
    
    [self presentViewController:alert animated:YES completion:nil];
    
   
}

#pragma mark-加载所有钱包
-(void)loadAllWallet{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    NSString *url = Get_load_wallets_URL;
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                NSArray *arr = responseObject[@"result"];
                if (self.allWalletArr.count>0) {
                    [self.allWalletArr removeAllObjects];
                }
                
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    FCWalletsModel *model = [FCWalletsModel mj_objectWithKeyValues:obj];
                    NSString *xidStr = [FCLocalUserHelper getXidStr];
                    model.XID = xidStr;
                    
                    if ([model.choice isEqualToString:@"1"]) {
                        
                        if ([self.cchStatus isEqualToString:@"0"]) {
                            
                            
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModel2 = model;
                                [self.arrMut addObject:self.walletModel2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModel3 = model;
                                [self.arrMut addObject:self.walletModel3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModel4 = model;
                                [self.arrMut addObject:self.walletModel4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModel5 = model;
                                [self.arrMut addObject:self.walletModel5];
                            }
                        }else{
                            if ([model.walletId isEqualToString:@"1009"]) {
                                self.walletModel1 = model;
                                [self.arrMut addObject:self.walletModel1];
                                
                            }
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModel2 = model;
                                [self.arrMut addObject:self.walletModel2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModel3 = model;
                                [self.arrMut addObject:self.walletModel3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModel4 = model;
                                [self.arrMut addObject:self.walletModel4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModel5 = model;
                                [self.arrMut addObject:self.walletModel5];
                            }
                        }
                        
                    
                    }
                }];
                wself.arrMut = [wself getAnArrayWithArray:self.arrMut];
                
                wself.allWalletArr = wself.arrMut;
                [self.tableView reloadData];
            }
            
        }
        
    } faile:^(NSError *error) {
        if (error ) {
            NSLog(@"%@",error);
        }
        
    }];
    
    
    
}
-(void)getCCHStatus{
    
    NSString *url = @"https://app.fund-chain.io/Fundchain/index.php/Api/Base/is_show_coin_1_0";
    [FCSharedNetworkTool POSTWithURLString:url parameters:nil success:^(id responseObject) {
        if (responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                NSLog(@"CCH是%@",responseObject[@"result"][@"show"]);
                NSString *res = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"show"]];
                FCCCHStatusModel *model = [FCCCHStatusModel new];
                model.statusStr = res;
                [FCLocalUserHelper saveCCHStatus:model];
                
            }
        }
        
        
    } faile:^(NSError *error) {
        
        
    }];
}
-(NSMutableArray *) getAnArrayWithArray:(NSMutableArray*)theArray
{
    NSMutableArray * mutableArray = [[NSMutableArray alloc]init];
    
    
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j<theArray.count; j++) {
            FCWalletsModel * modelj = theArray[j];
            if ([modelj.walletId isEqualToString:@"1009"] && i==0) {
                [mutableArray addObject:modelj];
                
            }
            if ([modelj.walletId isEqualToString:@"1001"] && i==1) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1006"] && i==2) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1005"] && i==3) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1010"] && i==4) {
                [mutableArray addObject:modelj];
            }
        }
    }
    return mutableArray;
}
-(NSMutableArray *)allWalletArr{
    if (!_allWalletArr) {
        _allWalletArr = [NSMutableArray new];
    }
    return _allWalletArr;
}
-(NSMutableArray *)arrMut{
    if (!_arrMut) {
        _arrMut = [NSMutableArray new];
    }
    return _arrMut;
}
@end

